package com.ews.onlineexchange.app;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;

import com.ews.onlineexchange.model.*;
import org.apache.commons.beanutils.BeanUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ews.onlineexchange.app.entity.ServiceSupplierBasicInfo;
import com.ews.onlineexchange.app.entity.SimpleBulletin;
import com.ews.onlineexchange.app.entity.SimpleBulletinTrade;
import com.ews.onlineexchange.app.entity.SimpleCert;
import com.ews.onlineexchange.app.entity.SimpleTradeTradeRating;
import com.ews.onlineexchange.app.entity.TempAgentService;
import com.ews.onlineexchange.app.entity.TempAttachment;
import com.ews.onlineexchange.app.entity.TempBulletin;
import com.ews.onlineexchange.app.entity.TempBusiness;
import com.ews.onlineexchange.app.entity.TempImage;
import com.ews.onlineexchange.app.entity.TempQualificationCert;
import com.ews.onlineexchange.app.entity.TempQualificationClass;
import com.ews.onlineexchange.app.entity.TempQualificationGroup;
import com.ews.onlineexchange.app.entity.TempQualificationLevel;
import com.ews.onlineexchange.app.entity.TempQualificationTemplate;
import com.ews.onlineexchange.app.entity.TempSector;
import com.ews.onlineexchange.app.entity.TempServiceSupplier;
import com.ews.onlineexchange.app.entity.TempTrade;
import com.ews.onlineexchange.app.entity.TempTradeRating;
import com.ews.onlineexchange.model.bulletinRequirement.Requirement;
import com.ews.onlineexchange.service.BulletinDiscardRecordService;
import com.ews.onlineexchange.service.DeterminedRecordService;
import com.ews.onlineexchange.service.MessgaePushService;
import com.ews.onlineexchange.service.SmsService;
import com.ews.onlineexchange.service.UserService;
import com.ews.onlineexchange.service.qualifier.MessagePushWsEvent;
import com.ews.onlineexchange.util.AttachmentType;
import com.ews.onlineexchange.util.AttachmentUtils;

@Named
public class AppService{
	
	public List<SimpleBulletin> getSimpleBulletinList(List<Bulletin> bulletinList,String type){
		  List<SimpleBulletin> sBulletinList = new ArrayList<>();
	        for (Bulletin bulletin : bulletinList) {
	        	SimpleBulletin sBulletin = new SimpleBulletin();
	        	sBulletin.setProjectName(bulletin.getProjectName());
	        	sBulletin.setSerialNumber(bulletin.getSerialNumber());
	        	sBulletin.setId(bulletin.getId());
	        	if("auditted".equals(type))sBulletin.setDistributeDate(bulletin.getAuditTime());
	        	if("publicity".equals(type))sBulletin.setDistributeDate(bulletin.getOverTime());
	        	if("zf".equals(type))sBulletin.setDistributeDate(bulletin.getAgreedBulletinDate());
	        	if("agreed".equals(type)) {
	        		Date overDate = bulletin.getOverTime();
	        		Calendar cal = Calendar.getInstance();
	        		cal.setTime(overDate);
	        		cal.set(Calendar.DAY_OF_MONTH,cal.get(Calendar.DAY_OF_MONTH)+1);
	        		Date newDate = cal.getTime();
	        		sBulletin.setDistributeDate(newDate);
	        	}
	        	sBulletin.setBulletinReqStr(bulletin.getBulletinReqStr());
	        	sBulletin.setId(bulletin.getId());
	        	sBulletinList.add(sBulletin);
			}
	      return sBulletinList;
	}
	@Inject
	BulletinDiscardRecordService bulletinDiscardRecordService;
	public TempBulletin getTempBulletin(Bulletin bulletin) {
		TempBulletin b = new TempBulletin();
		Field[] fields = b.getClass().getDeclaredFields();
		for (Field field : fields) {
			if(field.getType().toString().equals("interface java.util.List") || field.getType().toString().equals("class java.util.Date") || field.getType().toString().equals("class com.ews.onlineexchange.model.User")) {				
				continue;			
			}
			String fieldName = field.getName();
			if(fieldName.equals("serialVersionUID"))continue;
			try {
				BeanUtils.setProperty(b, fieldName, BeanUtils.getProperty(bulletin, fieldName));				
			} catch (Exception e) {
//				System.out.println("出错的字段="+fieldName);
//				e.printStackTrace();
				continue;
			}
		}
		b.setDistributeDate(bulletin.getCreateDate());
    	b.setApplyDoneTime(bulletin.getApplyDoneTime());
    	b.setAuditTime(b.getAuditTime());
    	b.setBuyer(bulletin.getBuyer());
    	b.setChooseTime(bulletin.getChooseTime());
    	b.setWayOfChoose(bulletin.getWayOfChoose());
    	b.setDoneTime(bulletin.getDoneTime());
    	b.setEndingApplyTime(bulletin.getEndingApplyTime());
    	b.setLimitUnit(bulletin.getLimitUnit());
    	b.setOverTime(bulletin.getOverTime());
    	b.setTimeSPan(bulletin.getTimeSPan());
    	if(null != bulletin.getSuccessTrade()) {
    		b.setSuccessSupplier(bulletin.getSuccessTrade().getSupplier().getCnname());
    	}
    	b.setTradeStatus(bulletin.getTradeStatus());
    	b.setQualificationStr(bulletin.getQualificationGroup().getQualificationGroupDetail());
    	List<QualificationGroup> agentServiceGroups = bulletin.getQualificationGroup().getAgentServiceGroups();
    	if(agentServiceGroups.size() > 0) {
    		List<TempQualificationGroup> tempQualificationGroups = new ArrayList<>();
    		for (QualificationGroup qualificationGroup : agentServiceGroups) {
				TempQualificationGroup tempQualificationGroup = new TempQualificationGroup();
				tempQualificationGroup.setRelation(qualificationGroup.getRelation());
				List<AgentService> agentServices = qualificationGroup.getAgentServices();
				List<TempAgentService> tempAgentServices = new ArrayList<>();
				for (AgentService agentService : agentServices) {
					TempAgentService tempAgentService = new TempAgentService();
					tempAgentService.setServiceName(agentService.getName());
					QualificationClass qClass = agentService.getQualificationClass();
					if(null != qClass) {
						tempAgentService.setQualificationClassName(qClass.getName());
					}
					tempAgentServices.add(tempAgentService);
				}
				tempQualificationGroup.setAgentServices(tempAgentServices);
				tempQualificationGroups.add(tempQualificationGroup);
			}
    		b.setAgentServiceGroups(tempQualificationGroups);
    	}
    	List<Attachment> atts = bulletin.getAttachments();
    	b.setAttachments(getTempAttachments(atts));
    	
    	List<Image> assessImages = bulletin.getAssessImages();
    	b.setAssessImages(getTempImages(assessImages));
    	List<Image> photos = bulletin.getPhotos();
    	b.setPhotos(getTempImages(photos));
    	b.setDiscardRecords(bulletinDiscardRecordService.getRecordsByBulletinId(bulletin.getId()));
    	List<Attachment> assessAttachments = bulletin.getAssessAttachments();
    	b.setAssessAttachments(getTempAttachments(assessAttachments));
    	b.setDefs(bulletin.getDefs());
    	List<Attachment> appliedDoneAttachments = bulletin.getAppliedDoneAttachments();
    	b.setAppliedDoneAttachments(getTempAttachments(appliedDoneAttachments));
    	b.setAppliedSuppliers(getTempServiceSupplierList(bulletin.getVerifiedTrades()));
    	b.setBestAppliedSuppliers(getTempServiceSupplierList(bulletin.getBestTrades()));
    	Trade successTrade = bulletin.getSuccessTrade();
    	b.setSuccessTradeSupplier(getTempServiceSupplierByTrade(successTrade));
		b.setVerifiedTrades(getTempTradeByTradeList(bulletin.getVerifiedTrades()));
    	return b;
		
	}
	
	
	public TempServiceSupplier getTempServiceSupplierByTrade(Trade trade) {
		if(trade != null) {
			TempServiceSupplier supplier = new TempServiceSupplier();
			supplier.setId(trade.getSupplier().getId());
			supplier.setCnname(trade.getSupplier().getCnname());
			return supplier;
		}else return null;
	}
	
	public List<TempTrade> getTempTradeByTradeList(List<Trade> trades) {
		List<TempTrade> tempTrades = new ArrayList<>();
		for (Trade trade : trades) {
			TempTrade tempTrade = new TempTrade();
			tempTrade.setSupplierId(trade.getSupplier().getId());
			tempTrade.setBulletinId(trade.getBulletin().getId());
			tempTrade.setOffer(trade.getOffer());
			tempTrade.setOfferCount(trade.getOfferCount());
			tempTrade.setSupplierName(trade.getSupplier().getCnname());
			tempTrades.add(tempTrade);
		}
		
		return tempTrades;
	}
	public TempTrade getTempTradeByTrade(Trade trade) {
			TempTrade tempTrade = new TempTrade();
			tempTrade.setSupplierId(trade.getSupplier().getId());
			tempTrade.setBulletinId(trade.getBulletin().getId());
			tempTrade.setOffer(trade.getOffer());
			tempTrade.setOfferCount(trade.getOfferCount());
			tempTrade.setSupplierName(trade.getSupplier().getCnname());
			tempTrade.setRequirements(getTempRequirements(trade.getRequirements()));
			return tempTrade;
	}
	public List<TempServiceSupplier> getTempServiceSupplierList(List<Trade> trades) {
		List<TempServiceSupplier> suppliers = new ArrayList<>();
    	for (Trade trade : trades) {
    		TempServiceSupplier supplier = new TempServiceSupplier();
    		supplier.setId(trade.getSupplier().getId());
    		supplier.setCnname(trade.getSupplier().getCnname());
    		suppliers.add(supplier);
		}
		 return suppliers;
	}
	public List<SimpleBulletinTrade> getSimpleBulletinList(List<Trade> tradeList){
		  List<SimpleBulletinTrade> sBulletinTradeList = new ArrayList<>();
	        for (Trade trade : tradeList) {
	        	Bulletin bulletin = trade.getBulletin();
	        	SimpleBulletinTrade sBulletinTrade = new SimpleBulletinTrade();
	        	sBulletinTrade.setCanCancel(trade.supplierCanCancel());
	        	sBulletinTrade.setProjectName(bulletin.getProjectName());
	        	sBulletinTrade.setSerialNumber(bulletin.getSerialNumber());
	        	sBulletinTrade.setBulletinId(bulletin.getId());
	        	sBulletinTrade.setTradeId(trade.getId());
	        	sBulletinTrade.setBuyerName(bulletin.getBuyer().getCnname());
	        	sBulletinTrade.setWayOfChoose(bulletin.getWayOfChoose().getTypeName());
	        	sBulletinTrade.setEndendingApplyTime(bulletin.getEndingApplyTime());
	        	sBulletinTradeList.add(sBulletinTrade);
			}
	      return sBulletinTradeList;
	}
	public List<SimpleTradeTradeRating> getSimpleTradeRatingList(List<Trade> tradeList){
		  List<SimpleTradeTradeRating> sBulletinTradeList = new ArrayList<>();
	        for (Trade trade : tradeList) {
	        	Bulletin bulletin = trade.getBulletin();
	        	SimpleTradeTradeRating sBulletinTrade = new SimpleTradeTradeRating();
	        	sBulletinTrade.setProjectName(bulletin.getProjectName());
	        	sBulletinTrade.setSerialNumber(bulletin.getSerialNumber());
	        	sBulletinTrade.setBulletinId(bulletin.getId());
	        	sBulletinTrade.setTradeId(trade.getId());
	        	sBulletinTrade.setBuyerName(bulletin.getBuyer().getCnname());
	        	sBulletinTrade.setWayOfChoose(bulletin.getWayOfChoose().getTypeName());
	        	TradeRating   tradeRating = trade.getTradeRating();
	        	if(tradeRating != null) {
	        		TempTradeRating tempoTradeRating = new TempTradeRating();
		        	tempoTradeRating.setQuality(tradeRating.getQuality());
		        	tempoTradeRating.setEffectiveness(tradeRating.getEffectiveness());
		        	tempoTradeRating.setAttitude(tradeRating.getAttitude());
		        	tempoTradeRating.setCharge(tradeRating.getCharge());
		        	tempoTradeRating.setStandard(tradeRating.getStandard());
		        	tempoTradeRating.setRatingDate(tradeRating.getRatingDate());
		        	AdditionalTradeRating additionalTradeRating = tradeRating.getAdditionalTradeRating();
					if(additionalTradeRating == null)tempoTradeRating.setAdditionalContent("");
					else tempoTradeRating.setAdditionalContent(additionalTradeRating.getContent());
		        	tempoTradeRating.setTradeId(trade.getId());
		        	sBulletinTrade.setTradeRating(tempoTradeRating);
	        	}
	        	
	        	sBulletinTradeList.add(sBulletinTrade);
	        	
			}
	      return sBulletinTradeList;
	}
	
	@Inject
	EntityManager entityManager;
	@Inject
	SmsService smsService;
	@Inject
	DeterminedRecordService recordService;
	@Inject
	UserService userService;
	
	@Inject
	@MessagePushWsEvent
	Event<String> messagePushWsEvent;
	
	@Inject
	MessgaePushService messgaePushService;
	public String applyTrade(String userId,String tradeId) {
		if(recordService.isExistSupplierInRecord(userId)) {
			return  "你公司参与项目选取资格已被暂停，待整改合格并提报诚信承诺书后，恢复项目选取资格。";
		}
		
		Trade trade = entityManager.find(Trade.class, tradeId);
		if(trade == null) {
			return  "未找到相应的交易，请检查参数是否正确！";
		}else {
			try {
				Bulletin bulletin = trade.getBulletin();
				if (bulletin.getEndingApplyTime().getTime() < new Date().getTime()) {
					return  "截止申请时间不能早于当前时间！"; 
				}
//				bulletin.setHasAppliedCount(bulletin.getAppliedCount()+1);
				entityManager.merge(bulletin);
				trade.setApply(true);
				trade.setApplyTime(new Date());
				trade.setHasVerify(true);
				trade.setVerifyTime(new Date());
				trade.setCancelAudit("0");
				entityManager.merge(trade);
				smsService.addSuccessAppliedMessageToSupplier(trade);
				//中介报名成功消息推送
//				String pushMessage = messgaePushService.addSuccessAppliedMessageToSupplier(trade);
//				messagePushWsEvent.fire(pushMessage);
				String msg = "报名成功!";
				if(bulletin.getWayOfChoose().equals(ChooseType.Average) || bulletin.getWayOfChoose().equals(ChooseType.Price)){
					msg += "请于选取时间截止前登录系统按照操作提示进行报价。";
				}
				return "报名成功";
			} catch (Exception e) {
				e.printStackTrace();
				return "出现错误，请稍后重试！";
			}
		}
	}	
	
	public String cancelTrade(String tradeId) {
		Trade trade = entityManager.find(Trade.class, tradeId);
		if(trade == null) {
			return  "未找到相应的交易，请检查参数是否正确！";
		}else {
			try {
				Bulletin bulletin = trade.getBulletin();
//				bulletin.setHasAppliedCount(bulletin.getAppliedCount() - 1);
				entityManager.merge(bulletin);
				trade.setApply(false);
				trade.setHasVerify(false);
				trade.setVerifyTime(null);
				trade.setApplyTime(null);
				trade.setRequirements(null);
				entityManager.merge(trade);
				//中介报名成功消息推送
				String pushMessage = messgaePushService.addCancelAppliedMessageToSupplier(trade);
				messagePushWsEvent.fire(pushMessage);
				return "取消报名成功！";
			} catch (Exception e) {
				e.printStackTrace();
				return "出现错误，请稍后重试！";
			}
		}
	}
	
	public List<TempAttachment> getTempAttachments(List<Attachment> attachments){
		List<TempAttachment> tempAttrs = new ArrayList<>();
		for (Attachment attachment : attachments) {
			TempAttachment tempAttr = new TempAttachment();
			tempAttr.setFileName(attachment.getFilename());
			tempAttr.setFullPath(attachmentUtils.getFullPath(attachment));
			tempAttr.setId(attachment.getId());
			tempAttrs.add(tempAttr);
		}
		return tempAttrs;
	}
	
	public List<TempBusiness> getTempBusinesses(List<MainBusiness> mainBusinesses){
		List<TempBusiness> tempBusinesses = new ArrayList<>();
		for (MainBusiness business : mainBusinesses) {
			TempBusiness tempBusiness = new TempBusiness();
			TempAgentService tempAgentService = new TempAgentService();
			AgentService agentService = business.getAgentService();
			if(agentService == null )continue;
			tempAgentService.setId(agentService.getId());
			tempAgentService.setQualificationClassName(agentService.getQualificationClass().getName());
			tempAgentService.setServiceName(agentService.getName());
			tempBusiness.setAgentService(tempAgentService);
			tempBusiness.setCommitOfPrice(business.getCommitOfPrice());
			tempBusiness.setCommitOfQuality(business.getCommitOfQuality());
			tempBusiness.setCommitOfTime(business.getCommitOfTime());
			tempBusiness.setImages(getTempImages(business.getImages()));
			tempBusinesses.add(tempBusiness);
		}
		return tempBusinesses;
	}
	
	public List<TempImage> getTempImages(List<Image> images){
		List<TempImage> tempImages = new ArrayList<>();
		for (Image image : images) {
			TempImage tempImage = new TempImage();
			tempImage.setFileName(image.getFilename());
			tempImage.setFullPath(attachmentUtils.getFullPath(image));
			tempImage.setId(image.getId());
			tempImages.add(tempImage);
		}
		return tempImages;
	}
	
	public ServiceSupplierBasicInfo getServiceSupplierBasicInfo(ServiceSupplier supplier) {
		ServiceSupplierBasicInfo supplierBasicInfo = new ServiceSupplierBasicInfo();
		Field[] fields = supplierBasicInfo.getClass().getDeclaredFields();
		for (Field field : fields) {
			if(field.getType().toString().equals("interface java.util.List") || field.getType().toString().equals("class java.util.Date") || field.getType().toString().equals("class com.ews.onlineexchange.model.User")) {				
				continue;			
			}
			String fieldName = field.getName();
			if(fieldName.equals("serialVersionUID"))continue;
			try {
				BeanUtils.setProperty(supplierBasicInfo, fieldName, BeanUtils.getProperty(supplier, fieldName));				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		supplierBasicInfo.setCreditLevel(supplier.getCreditLevel().getTypeName());
		supplierBasicInfo.setCurrRejectRecord(supplier.getCurrRejectRecord());
		supplierBasicInfo.setAuditDate(supplier.getAuditDate());
		supplierBasicInfo.setAuditUser(supplier.getAuditUser());
		supplierBasicInfo.setRegtime(supplier.getRegtime());
		supplierBasicInfo.setBusnissAllotedTime(supplier.getBusnissAllotedTime());
		List<Attachment> attachments = supplier.getAttachments();
		List<Image>		 businessLicenseImages = supplier.getBusinessLicenseImages();
		//纳税证明已删除
//		List<Image> taxProveImages = supplier.getTaxProveImages();
		supplierBasicInfo.setAttachments(getTempAttachments(attachments));
		supplierBasicInfo.setBusinessLicenseImages(getTempImages(businessLicenseImages));
//		supplierBasicInfo.setTaxProveImages(getTempImages(taxProveImages));
		
//		
		
		return supplierBasicInfo;
	}
	
	public List<TempBusiness> getServiceSupplierBusinesses(ServiceSupplier supplier) {
		return getTempBusinesses( supplier.getMainBusinesses() );
	}
	
	public List<TempQualificationCert> getServiceSupplierCerts(ServiceSupplier supplier) {
		return getTempCerts(supplier.getCerts(),true,false);
	}
	
	public TempQualificationCert getTempCert(QualificationCert cert) {
		TempQualificationCert tempCert = new TempQualificationCert();
		tempCert.setId(cert.getId());
		tempCert.setAllotedDate(cert.getAllotedDate());
		tempCert.setApproveDate(cert.getApproveDate());
		tempCert.setApproveDepartmentName(cert.getApproveDepartmentName());
		tempCert.setApproveLicenseNo(cert.getApproveLicenseNo());
		tempCert.setAuditResult(cert.getAuditResult());
		tempCert.setAuditTime(cert.getAuditTime());
		tempCert.setContactor(cert.getContactor());
		tempCert.setContactorPhoneNumber(cert.getContactorPhoneNumber());
		tempCert.setCurrRejectRecord(cert.getCurrRejectRecord());
		tempCert.setHistoryRejectRecords(cert.getHistoryRejectRecords());
		tempCert.setServiceSupplierName(cert.getServiceSupplier().getCnname());
		tempCert.setValid(cert.isValid());
		if(null != cert.getProfessionUser())tempCert.setAuditUserName(cert.getProfessionUser().getCnname());
		List<Attachment> attachments = cert.getServiceSupplier().getAttachments();
		List<TempAttachment> tempAttrs = getTempAttachments(attachments);
		tempCert.setAttachments(tempAttrs);
		List<Image> certPhotos = cert.getCertPhotos();
		tempCert.setCertPhotos(getTempImages(certPhotos));
		tempCert.setQualificationTemplates(getTempQualificationTempates(cert.getQualificationTemplates(),true));
		return tempCert;
	}
	
	public TempServiceSupplier getPublicServiceSupplierFullInfo(ServiceSupplier supplier) {
		TempServiceSupplier tempSupplier = new TempServiceSupplier();
		Field[] fields = tempSupplier.getClass().getDeclaredFields();
		for (Field field : fields) {
			if(field.getType().toString().equals("interface java.util.List") || field.getType().toString().equals("class java.util.Date") || field.getType().toString().equals("class com.ews.onlineexchange.model.User")) {				
				continue;			
			}
			String fieldName = field.getName();
			if(fieldName.equals("serialVersionUID"))continue;
			try {
				BeanUtils.setProperty(tempSupplier, fieldName, BeanUtils.getProperty(supplier, fieldName));				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
//		tempSupplier.setAuditDate(supplier.getAuditDate());
//		tempSupplier.setAuditUser(supplier.getAuditUser());
		tempSupplier.setRegtime(supplier.getRegtime());
		tempSupplier.setBusnissAllotedTime(supplier.getBusnissAllotedTime());
//		List<Attachment> attachments = supplier.getAttachments();
		List<MainBusiness>	 mainBusinesses = supplier.getMainBusinesses();
		List<Image>		 businessLicenseImages = supplier.getBusinessLicenseImages();		
		//由于是前台展示，只展示有效的证书
		List<QualificationCert> certs = supplier.getValidCerts();
//		List<Image> taxProveImages = supplier.getTaxProveImages();
//		tempSupplier.setAttachments(getTempAttachments(attachments));
		tempSupplier.setBusinesses(getTempBusinesses(mainBusinesses));
		tempSupplier.setBusinessLicenseImages(getTempImages(businessLicenseImages));
//		tempSupplier.setTaxProveImages(getTempImages(taxProveImages));
		
		tempSupplier.setCerts(getTempCerts(certs,false,false));
//		
		
		return tempSupplier;
	}
	
	public List<TempQualificationCert> getTempCerts(List<QualificationCert> certs,boolean simple,boolean showPhoto){
		List<TempQualificationCert> tempCerts = new ArrayList<>();
		for (QualificationCert cert : certs) {
			TempQualificationCert tempCert = new TempQualificationCert();
			tempCert.setId(cert.getId());
			tempCert.setAllotedDate(cert.getAllotedDate());
			tempCert.setApproveDate(cert.getApproveDate());
			tempCert.setApproveDepartmentName(cert.getApproveDepartmentName());
			tempCert.setApproveLicenseNo(cert.getApproveLicenseNo());
			tempCert.setAuditResult(cert.getAuditResult());
			tempCert.setAuditTime(cert.getAuditTime());
			tempCert.setContactor(cert.getContactor());
			tempCert.setContactorPhoneNumber(cert.getContactorPhoneNumber());
			tempCert.setCurrRejectRecord(cert.getCurrRejectRecord());
//			tempCert.setHistoryRejectRecords(cert.getHistoryRejectRecords());
			tempCert.setServiceSupplierName(cert.getServiceSupplier().getCnname());
			tempCert.setValid(cert.isValid());
			if(null != cert.getProfessionUser())tempCert.setAuditUserName(cert.getProfessionUser().getCnname());
			if(!simple) {
				tempCert.setHidden(cert.isHidden());
				if(showPhoto) {
					List<Image> certPhotos = cert.getCertPhotos();
					tempCert.setCertPhotos(getTempImages(certPhotos));
				}
				tempCert.setQualificationTemplates(getTempQualificationTempates(cert.getQualificationTemplates(),false));
				
			}
			QualificationClass qualificationClass = cert.getQualificationClass();
			TempQualificationClass tempQualificationClass = new TempQualificationClass();
			tempQualificationClass.setAuditDepartmentName(qualificationClass.getAuditDepartment().getCnname());
			tempQualificationClass.setId(qualificationClass.getId());
//			List<QualificationLevel> sortedLevelOptions = qualificationClass.getSortedLevelOptions();
//			tempQualificationClass.setLevelOptions(getTempLevels(sortedLevelOptions));
			tempQualificationClass.setName(qualificationClass.getName());
//			Set<Sector> rootSectors = qualificationClass.getRootSectors();
//			tempQualificationClass.setRootSectors(rootSectors);
			tempQualificationClass.setSectorNames(qualificationClass.getSectorNames());
			tempCert.setQualificationClass(tempQualificationClass);
			tempCerts.add(tempCert);		
		}
		return tempCerts;
	}
	
	public List<SimpleCert> getSimpleCert(List<QualificationCert> certs){
		List<SimpleCert> simpleCerts = new ArrayList<>();
		for (QualificationCert cert : certs) {
			SimpleCert simpleCert = new SimpleCert();
			Date all = cert.getAllotedDate();
			simpleCert.setAllotedDate(new Date(all.getTime()));
			ProfessionUser professionUser = cert.getProfessionUser();
			if(null != professionUser)simpleCert.setAuditor(professionUser.getCnname());
			else simpleCert.setAuditor("");
			
			simpleCert.setCertId(cert.getId());
			simpleCert.setQualificationClassName(cert.getQualificationClass().getName());
			simpleCert.setSupplierId(cert.getServiceSupplier().getId());
			simpleCert.setSupplierName(cert.getServiceSupplier().getCnname());
			simpleCert.setUpdateDate(cert.getUpdateDate());
			simpleCerts.add(simpleCert);
		}
		return simpleCerts;
	}
	
	public List<TempQualificationTemplate> getTempQualificationTempates(List<QualificationTemplate> tempLates,boolean isProfession){
		List<TempQualificationTemplate> tempQualificationTemplates = new ArrayList<>();
		for (QualificationTemplate qualificationTemplate : tempLates) {
			TempQualificationTemplate tempQualificationTemplate = new TempQualificationTemplate();
			tempQualificationTemplate.setId(qualificationTemplate.getId());
			tempQualificationTemplate.setQualificationClass(getTempQualificationClass(qualificationTemplate.getQualificationClass()));
			tempQualificationTemplate.setQualificationLevel(getTempQualificationLevel(qualificationTemplate.getQualificationLevel()));
			if(isProfession) {
				Set<TempSector> treeSector =  getTempSectors(qualificationTemplate.getTreeSectors());
				tempQualificationTemplate.setTreeSector(treeSector);
			}else {
				tempQualificationTemplate.setSectors(getTempSectors(qualificationTemplate.getSectors()));
			}
			tempQualificationTemplates.add(tempQualificationTemplate);
		}
		return tempQualificationTemplates;
	}
	
	public List<TempRequirement> getTempRequirements(List<Requirement> requirements){
		List<TempRequirement> tempRequirements = new ArrayList<>();
		for (Requirement requirement : requirements) {
			TempRequirement tempRequirement = new TempRequirement();
			tempRequirement.setAttachments(getTempAttachments(requirement.getAttachments()));
			tempRequirement.setId(requirement.getId());
			tempRequirement.setImages(getTempImages(requirement.getImages()));
			tempRequirement.setRequirementDefination(requirement.getRequirementDefination());
			tempRequirements.add(tempRequirement);
		}
		return tempRequirements;
	}
	
	public List<TempSector> getTempSectors(List<Sector> sectors){
		List<TempSector> tempSectors = new ArrayList<>();
		for (Sector sector : sectors) {
			TempSector tempSector = new TempSector();
			tempSector.setId(sector.getId());
			tempSector.setFullSectorName(sector.getFullSectorName());
			tempSectors.add(tempSector);
		}
		
		return tempSectors;
	}
	
	public Set<TempSector> getTempSectors(Set<Sector> sectors){
		Set<TempSector> tempSectors = new HashSet<>();
		for (Sector sector : sectors) {
			TempSector tempSector = new TempSector();
			tempSector.setId(sector.getId());
			tempSector.setSectorName(sector.getSectorName());
			tempSector.setSectorLevel(sector.getLevel());
			tempSector.setSno(sector.getSno());
			tempSectors.add(tempSector);
		}
		Set<TempSector> resultSet = new TreeSet<>(new Comparator<TempSector>() {
			@Override
			public int compare(TempSector o1, TempSector o2) {
				return o1.getSno().compareTo(o2.getSno());
			}
		});
		for (TempSector sector : tempSectors) {
			resultSet.add(sector);
		}
		return resultSet;
	}
	
	public TempQualificationClass getTempQualificationClass(QualificationClass qualificationClass) {
		TempQualificationClass tempClass = new TempQualificationClass();
		tempClass.setAuditDepartmentName(qualificationClass.getAuditDepartment().getCnname());
		tempClass.setId(qualificationClass.getId());
		tempClass.setName(qualificationClass.getName());
//		tempClass.setSectorNames(qualificationClass.getSectorNames());
		return tempClass;
	}
	public Set<TempQualificationLevel> getTempLevels(List<QualificationLevel> levels){
		Set<TempQualificationLevel> tempLevels = new HashSet<>();
		for (QualificationLevel qualificationLevel : levels) {
			tempLevels.add(getTempQualificationLevel(qualificationLevel));
		}
		
		return tempLevels;
	}
	
	public TempQualificationLevel getTempQualificationLevel(QualificationLevel qualificationLevel) {
		TempQualificationLevel tempLevel = new TempQualificationLevel();
		tempLevel.setId(qualificationLevel.getId());
		tempLevel.setName(qualificationLevel.getName());
		tempLevel.setValue(qualificationLevel.getValue());
		return tempLevel;
	}
//	public Set<TempSector> getTempSectors(Set<Sector> sectors){
//		Set<TempSector> tempSectors = new HashSet<>();
//		for (Sector sector : sectors) {
//			TempSector tempSector = new TempSector();
//			tempSector.setId(sector.getId());
//			tempSector.
//		}
//		
//		
//		
//		return tempSectors;
//	}
	
	public static void main(String[] args) {
		String defId = "";
		String defsStr = "{\"402881a06f3af9b0016f4a3421c70138\":[{\"filename\":\"数据目录 20191126.xlsx\",\"size\":15325,\"result\":\"UEsDBBQABgAIAAAAIQCq91ikegEAABQGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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JLwQAAAEIBAAAjAAAAAAAAAAAAAAAAAIURAAB4bC93b3Jrc2hlZXRzL19yZWxzL3NoZWV0MS54bWwucmVsc1BLAQItABQABgAIAAAAIQBoIkoweQEAAKICAAAYAAAAAAAAAAAAAAAAAIcSAAB4bC93b3Jrc2hlZXRzL3NoZWV0Mi54bWxQSwECLQAUAAYACAAAACEAaCJKMHkBAACiAgAAGAAAAAAAAAAAAAAAAAA2FAAAeGwvd29ya3NoZWV0cy9zaGVldDMueG1sUEsBAi0AFAAGAAgAAAAhAFRGAFddEQAAd2AAABgAAAAAAAAAAAAAAAAA5RUAAHhsL3dvcmtzaGVldHMvc2hlZXQxLnhtbFBLAQItABQABgAIAAAAIQBakdIvmwYAAAIyAAAUAAAAAAAAAAAAAAAAAHgnAAB4bC9zaGFyZWRTdHJpbmdzLnhtbFBLAQItABQABgAIAAAAIQCRjud+2QMAAPYUAAANAAAAAAAAAAAAAAAAAEUuAAB4bC9zdHlsZXMueG1sUEsBAi0AFAAGAAgAAAAhABtAWtqjAQAARgMAABAAAAAAAAAAAAAAAAAASTIAAGRvY1Byb3BzL2FwcC54bWxQSwECLQAUAAYACAAAACEANUBCQDgAAADcAAAAJwAAAAAAAAAAAAAAAAAiNQAAeGwvcHJpbnRlclNldHRpbmdzL3ByaW50ZXJTZXR0aW5nczEuYmluUEsBAi0AFAAGAAgAAAAhAJp+NOw/AQAAUQIAABEAAAAAAAAAAAAAAAAAnzUAAGRvY1Byb3BzL2NvcmUueG1sUEsFBgAAAAAOAA4AsgMAABU4AAAAAA==\"}]}";
		String jsonArrayStr = getJsonArrayStrByDefId(defId,defsStr);
		System.out.println(jsonArrayStr);
	}
	
	public static String getJsonArrayStrByDefId(String defId,String defsStr) {
		JSONObject json = JSONObject.parseObject(defsStr);
		if(json == null) return "";
		else return json.getString(defId);
	}
	public List<Attachment> getAttachmentListFromJsonArrayStr(String jsonArrayStr) {
		JSONArray subjectIdPhotosArr = JSONArray.parseArray(jsonArrayStr);
		List<Attachment> attachments = new ArrayList<>();
		for (Object obj : subjectIdPhotosArr) {
			String jsonStr = JSONObject.toJSONString(obj);
			Attachment attr = getAttachmentFromJsonStr(jsonStr);
			attachments.add(attr);
		}
		return attachments;
	}
	@Inject
	AttachmentUtils attachmentUtils;
	public Attachment getAttachmentFromJsonStr(String jsonStr) {
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		String  fileName = jsonObj.getString("fileName");
		long 	size    = jsonObj.getLongValue("size");
		String dataAttachmentString = jsonObj.getString("result");
		byte[] data = Base64.getDecoder().decode(dataAttachmentString.substring(dataAttachmentString.indexOf(",") + 1));
		Attachment attr = new Attachment();
		JSONObject fileInfo = attachmentUtils.getFileInfo(fileName,AttachmentType.Image, null);
		String diskFileName = fileInfo.getString("diskFileName");
		String filepath = fileInfo.getString("filepath");
		attr.setFilepath(filepath);
		attr.setDiskFileName(diskFileName);
		attr.setFilename(fileName);
		attr.setFilesize(size);
		attachmentUtils.saveFileToDisk(filepath, data);
		return attr;
	}
}
